package com.anxin.act.busFlow.web;

import com.anxin.act.busFlow.dto.AddInvestDTO;
import com.anxin.act.busFlow.entity.WfBusNode;
import com.anxin.act.busFlow.entity.WfBusRound;
import com.anxin.act.busFlow.service.WfBusNodeEvolveService;
import com.anxin.act.busFlow.service.WfBusNodeService;
import com.anxin.act.busFlow.service.WfBusRoundService;
import com.anxin.framework.aspectj.lang.annotation.Log;
import com.anxin.framework.aspectj.lang.enums.BusinessType;
import com.anxin.framework.web.controller.BaseController;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.sys.file.entity.FileBase;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 业务节点Controller
 *
 * @author 刘翔宇
 * @date 2020-04-15
 */
//@Api(tags = "业务节点" )
@RestController
@RequestMapping("/node/wfBusNode")
public class WfBusNodeController extends BaseController{

    @Autowired
    private WfBusNodeService wfBusNodeService;

    @Autowired
    private WfBusRoundService wfBusRoundService;

    //@ApiOperation(value="根据ID查询node表记录" ,notes="作者:刘翔宇")
    @GetMapping("/getWfBusNode/{id}")
    @Log(title = "根据ID查询node表记录", businessType = BusinessType.LIST)
    public AjaxResult<WfBusNode> getWfBusNode(@PathVariable("id")String id) {
        return AjaxResult.success(wfBusNodeService.get(id));
    }

    /**
     * 查询一级节点
     */
    //@ApiOperation(value="查询一级节点" ,notes="作者:刘翔宇")
    @GetMapping("/getParentNode")
    @Log(title = "查询一级节点", businessType = BusinessType.LIST)
    public AjaxResult<List<WfBusNode>> getParentNode(WfBusNode wfBusNode){
        return wfBusNodeService.getParentNode(wfBusNode);
    }

    /**
     * 查询二级节点
     * @return
     */
    //@ApiOperation(value="查询二级节点" ,notes="作者:刘翔宇")
    @GetMapping("/getChildrenNode")
    @Log(title = "查询二级节点", businessType = BusinessType.LIST)
    public AjaxResult<List<WfBusNode>> getChildrenNode(WfBusNode wfBusNode){
        wfBusNode.setLatest("Y");
        List<WfBusNode> nodeList = wfBusNodeService.findList(wfBusNode);
        AjaxResult ajaxResult = AjaxResult.success(nodeList);
        ajaxResult.put("currentChildIndex",wfBusNodeService.getCurrentChildNode(nodeList));
        return ajaxResult;

    }


    /**
     * 获取form表单组件的地址
     * @return
     */
    //@ApiOperation(value="获取form表单组件的地址" ,notes="作者:刘翔宇")
    @GetMapping("/getNodeFormUrl")
    @Log(title = "获取form表单组件的地址", businessType = BusinessType.LIST)
    public AjaxResult getNodeFormUrl(WfBusNode wfBusNode){
        return wfBusNodeService.getNodeFormUrl(wfBusNode);
    }

    /**
     * 绑定dataId
     * @param id wfbusNode表的Id
     * @param dataId 数据ID
     * @return
     */
    //@ApiOperation(value="绑定dataId" ,notes="作者:刘翔宇")
    @GetMapping("/bindingDataId")
    @Log(title = "绑定dataId", businessType = BusinessType.UPDATE)
    public AjaxResult bindingDataId(@RequestParam(value="id",required = true) String id,@RequestParam(value="dataId",required = true) String dataId){
        return wfBusNodeService.bindingDataId(id,dataId);
    }

    /**
     * 获取节点审批的历史记录
     * @param id
     * @return
     */
    //@ApiOperation(value="获取节点审批的历史记录" ,notes="作者:刘翔宇")
    @GetMapping("/getHistoryApproval/{id}")
    @Log(title = "获取节点审批的历史记录", businessType = BusinessType.LIST)
    public AjaxResult<List<WfBusNode>> getHistoryApproval(@PathVariable("id")String id){
        return wfBusNodeService.getHistoryApproval(id);
    }

    /**
     * 获取当前节点表单中上传的附件
     * @param id wf_bus_node表中的ID
     * @return 表单中上传的附件集合
     */
    //@ApiOperation(value="获取当前节点表单中上传的附件" ,notes="作者:刘翔宇")
    @GetMapping("/getFileById/{id}")
    @Log(title = "获取当前节点表单中上传的附件", businessType = BusinessType.IMPORT)
    public AjaxResult<List<FileBase>> getFileById(@PathVariable("id")String id){
        return AjaxResult.success(wfBusNodeService.getFileById(id));
    }

    /**
     * 再次启动
     * @param id wf_bus_node表中的ID
     * @return
     */
    //@ApiOperation(value="绑定dataId" ,notes="作者:刘翔宇")
    @GetMapping("/restart/{id}")
    @Log(title = "绑定dataId", businessType = BusinessType.UPDATE)
    public AjaxResult restart(@PathVariable("id")String id){
        return wfBusNodeService.restart(id);
    }

    /**
     * 校验节点是否可以提交下一阶段
     * @param id 一级节点ID
     * @return
     */
    //@ApiOperation(value="校验节点是否可以提交下一阶段" ,notes="作者:刘翔宇")
    @GetMapping("/checkCommitNextNode/{id}")
    @Log(title = "校验节点是否可以提交下一阶段", businessType = BusinessType.LIST)
    public AjaxResult checkCommitNextNode(@PathVariable("id")String id){
        return wfBusNodeService.checkCommitNextNode(id);
    }

    /**
     * 根据业务ID校验节点是否可以提交下一阶段
     * @param busId 一级节点ID
     * @return
     */
    //@ApiOperation(value="根据业务ID校验节点是否可以提交下一阶段" ,notes="作者:刘翔宇")
    @GetMapping("/checkCommitNextNodeByBusId/{busId}")
    public AjaxResult checkCommitNextNodeByBusId(@PathVariable("busId")String busId){
        return wfBusNodeService.checkCommitNextNodeByBusId(busId);
    }


    //@ApiOperation(value="提交下一节点" ,notes="作者:刘翔宇")
    @GetMapping("/commitNextNode/{id}")
    @Log(title = "提交下一节点", businessType = BusinessType.UPDATE)
    public AjaxResult commitNextNode(@PathVariable("id")String id){
        return wfBusNodeService.commitNextNode(id);
    }


    //@ApiOperation(value="流程豁免" ,notes="作者:刘翔宇")
    @GetMapping("/immunityProcess/{id}")
    @Log(title = "流程豁免", businessType = BusinessType.UPDATE)
    public AjaxResult<String> immunityProcess(@PathVariable("id")String id){
        return wfBusNodeService.immunityProcess(id);
    }

    //@ApiOperation(value="获取首轮投资名称" ,notes="作者:刘翔宇")
    @GetMapping("/getFirstInvestName/{busId}")
    @Log(title = "获取首轮投资名称", businessType = BusinessType.LIST)
    public AjaxResult<String> getFirstInvestName(@PathVariable("busId")String busId){
        return AjaxResult.setSuccessData(wfBusRoundService.getFirstInvestName(busId));
    }

    //@ApiOperation(value="保存投资轮次" ,notes="作者:刘翔宇")
    @PostMapping("/saveInvestRound")
    @Log(title = "保存投资轮次", businessType = BusinessType.SAVE)
    public AjaxResult<WfBusRound> saveInvestRound(AddInvestDTO addInvestDTO){
        return wfBusNodeService.saveInvestRound(addInvestDTO);
    }

}
